{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": [],
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/WASasquatch/noodle-soup-prompts/blob/main/Noodle_Soup_Prompts_Prompt_Terminology_Generator_v3_0.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "# <img src=\"\"> <font size=\"6\">**Noodle Soup Prompts** v3.0</font> <font size=\"5\">- Prompt Terminology Generator</font> ![visitors](https://visitor-badge.glitch.me/badge?page_id=Noodle-Soup-Prompts&left_color=blue&right_color=orange) <img src=\"\">\n",
        "\n",
        "This tool contains a *growing* database of terminology to help build interesting prompts for [Disco Diffusion](https://discodiffusion.com/). **Give it a try!**\n",
        "\n",
        "Artist names gathered by **MisterRuffian** <font size=\"2\">(<font color=\"7e87f6\">Discord</font> Misterruffian#2891)</font> on his amazing [Latent Artist & Modifier Encyclopedia](https://docs.google.com/spreadsheets/d/1_jgQ9SyvUaBNP1mHHEzZ6HhL_Es1KwBKQtnpnmWW82I/).\n",
        "\n",
        "Terminology Database created by **WAS**asquatch <font size=\"2\">(<font color=\"7e87f6\">Discord</font>: WAS\\#0263)</font>\n",
        "\n",
        "\n",
        "## Other Tools\n",
        "\n",
        "- [Easy Diffusion](https://rebrand.ly/easy-diffusion) - A fork of [NOP's Stable Diffusion notebook](https://colab.research.google.com/drive/1jUwJ0owjigpG-9m6AI_wEStwimisUE17#scrollTo=_ekR-LW6trWG), packed full of features. \n",
        "- [DiscoStream](https://rebrand.ly/discostream) - A new fork of Disco Diffusion designed to be a little easier to use, with advanced functionality. It also includes GO BIG v2!\n",
        "- [OpenAI Guided Diffusion - Model Training / Fine-Tuning](https://rebrand.ly/guided-diffusion) - A implementation of OpenAI's Guided Diffusion on Google Colabs\n",
        "- [Portrait Playground](https://rebrand.ly/portrait-playground) - A version of Disco Diffusion with all current Portrait Generator Models.\n",
        "- [Portrait Generator `init_image` Prep](https://rebrand.ly/dd-image-prep) - Prep portraits or other `init_images` as approximations for better DD improvisation.  \n"
      ],
      "metadata": {
        "id": "kLh-sLUHfdrU"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "# Process Text Prompts"
      ],
      "metadata": {
        "id": "zUhk7BO2n1Yk"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "from genericpath import exists\n",
        "#@markdown ## [Terminology Noodle Wiki](https://github.com/WASasquatch/noodle-soup-prompts/wiki/Terminology-Reference)\n",
        "#@title <font size=\"\">3) Cook up some Noodle Soup</font>\n",
        "#@markdown *Run this cell to return your processed prompt*<br>\n",
        "#@markdown Use `|` to deliminate a new list element *(only valid for Disco Diffusion / DiscoStream)*\n",
        "import random, subprocess, time, json\n",
        "\n",
        "class log:\n",
        "    f = lambda color: lambda string: print(color + string + \"\\33[0m\")\n",
        "    black = f(\"\\33[30m\")\n",
        "    red = f(\"\\33[31m\")\n",
        "    green = f(\"\\33[32m\")\n",
        "    yellow = f(\"\\33[33m\")\n",
        "    blue = f(\"\\33[34m\")\n",
        "    megenta = f(\"\\33[35m\")\n",
        "    cyan = f(\"\\33[36m\")\n",
        "    white = f(\"\\33[37m\")\n",
        "\n",
        "try:\n",
        "    import nsp_pantry\n",
        "    from nsp_pantry import nsp_parse\n",
        "except ImportError:\n",
        "    print(subprocess.run(['wget', '-q', '--show-progress', '--no-cache', '--backups=1', 'https://raw.githubusercontent.com/WASasquatch/noodle-soup-prompts/main/nsp_pantry.py'], stdout=subprocess.PIPE).stdout.decode('utf-8'))\n",
        "finally:\n",
        "    import nsp_pantry\n",
        "    from nsp_pantry import nsp_parse\n",
        "\n",
        "#@markdown ---\n",
        "prompt = 'Portrait of a _adj-beauty_ _noun-emote_ _body-fit_ _nationality_ woman from _pop-culture_ in _pop-location_  by _artist_, _site_ | Intricate Detail, Elaborate Desings, HD, 8k resolution' #@param{type: 'string'}\n",
        "bowls_of_soup = 5 #@param {type: 'number'}\n",
        "#@markdown &nbsp;&nbsp;&nbsp;&nbsp;**bowls_of_soup:** *How many prompt iterations should we run?*\n",
        "output_mode = 'Stable Diffusion' #@param['Stable Diffusion', 'Disco Diffusion / DiscoStream']\n",
        "save_text_file = True #@param{type: 'boolean'}\n",
        "\n",
        "text_file_list = []\n",
        "\n",
        "displayPrint = True\n",
        "if output_mode == 'Disco Diffusion / DiscoStream':\n",
        "    prompt = [x.strip() for x in prompt.split('|')]\n",
        "    if type(prompt) is list:\n",
        "        displayPrint = False\n",
        "        text_file_list = {}\n",
        "\n",
        "log.green(\"TEXT PROMPTS CODE:\")\n",
        "for i in range(1, bowls_of_soup+1):\n",
        "    log.blue(\"\\n\\033[1mTEXT PROMPT \"+str(i)+\":\\033[0m\")\n",
        "    if displayPrint:\n",
        "        pprompt = nsp_parse(prompt)\n",
        "        if save_text_file:\n",
        "            text_file_list.append(pprompt)\n",
        "        print(pprompt)\n",
        "    else:\n",
        "        prompt = nsp_parse(prompt)\n",
        "        if save_text_file:\n",
        "            text_file_list[i] = prompt\n",
        "        print('[')\n",
        "        for i in range(len(prompt)):\n",
        "            deliminator = ',' if i != len(prompt)-1 else ''\n",
        "            print(f'    \\'{prompt[i]}\\'{deliminator}')\n",
        "        print(']')\n",
        "\n",
        "\n",
        "if save_text_file:\n",
        "    if displayPrint:\n",
        "        with open(f'prompts_{str(int(time.time()))}.txt', 'w') as f:\n",
        "            for p in text_file_list:\n",
        "                f.write(p)\n",
        "                f.write('\\n')\n",
        "    else:\n",
        "        with open(f'prompts_{str(int(time.time()))}.txt', 'w') as f:\n",
        "            f.write(json.dumps(text_file_list, indent=4))\n"
      ],
      "metadata": {
        "id": "jxcwZwnZ4UxR",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "26b93fb4-6c7f-4c50-fc80-ab0d0c4a6b5e",
        "cellView": "form"
      },
      "execution_count": 3,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "\u001b[32mTEXT PROMPTS CODE:\u001b[0m\n",
            "\u001b[34m\n",
            "\u001b[1mTEXT PROMPT 1:\u001b[0m\u001b[0m\n",
            "Portrait of a appealing Bored sound Papua New Guinean woman from Code Geass in Vancouver, Canada  by Bertil Nilsson, trending on Unsplash | Intricate Detail, Elaborate Desings, HD, 8k resolution\n",
            "\u001b[34m\n",
            "\u001b[1mTEXT PROMPT 2:\u001b[0m\u001b[0m\n",
            "Portrait of a good-looking Optimistic sinewy Icelandic woman from WarCraft in Machu Picchu, Peru  by Miriam Schapiro, trending on Behance | Intricate Detail, Elaborate Desings, HD, 8k resolution\n",
            "\u001b[34m\n",
            "\u001b[1mTEXT PROMPT 3:\u001b[0m\u001b[0m\n",
            "Portrait of a radiant Disgusted developed Nepalese woman from Pulp Fiction in Tokyo, Japan  by Anton Corbijn, trending on Saatchi Art | Intricate Detail, Elaborate Desings, HD, 8k resolution\n",
            "\u001b[34m\n",
            "\u001b[1mTEXT PROMPT 4:\u001b[0m\u001b[0m\n",
            "Portrait of a alluring Optimistic strong British Virgin Islander woman from The Simpsons in Matterhorn, Switzerland  by Donato Giancola, trending on Flickr | Intricate Detail, Elaborate Desings, HD, 8k resolution\n",
            "\u001b[34m\n",
            "\u001b[1mTEXT PROMPT 5:\u001b[0m\u001b[0m\n",
            "Portrait of a studly Indifferent Herculean Guyanese woman from Earthworm Jim in Hong Kong  by Rockwell Kent, trending on Sketchfab | Intricate Detail, Elaborate Desings, HD, 8k resolution\n"
          ]
        }
      ]
    }
  ]
}